/*************************************************************
	Class:		flash text
	Version:	1.0
	Author:		Samuel Birch
*************************************************************/
var flashText = new Class({
	
	Implements: [Options,Events],
	
	getOptions: function(){
		return {
			font: '/_common/swf/custom.swf'
		};
	},
	
	initialize: function(elements, options){
		this.setOptions(this.getOptions(), options);
		this.elements = $$(elements);
		this.properties = [];
		
		this.elements.each(function(el, i){
			
			var props = {
				'colour': el.getStyle('color').replace('#',''),
				'size': el.getStyle('fontSize').toInt(),
				'text': el.get('html')
			};
			this.properties.push(props);
			
			el.addClass('flashText');
			
			this.addFlash(el, props);
			
		}, this);
		
		new textResizeDetector({
			_onChange: this.update.bind(this)
		});
		
	},
	
	addFlash: function(el, props){
		var obj = new Swiff(this.options.font, {
			container: el,
			version: 8,
			width: '100%',
			height: '100%',//size.height+10,
			params: {
				wMode: 'transparent'
			},
			vars: {
				text: props.text,
				colour: props.colour,
				size: props.size
			},
			properties: {
				style: 'outline:none;'
			}
		});
	},
	
	update: function(defaultSize, newSize, oldSize){
		var percent = ((newSize / oldSize) * 100).toInt();
		if(oldSize){
			this.elements.each(function(el, i){
				el.getChildren().destroy();
				var props = this.properties[i];
					props.size = ((percent/100)*props.size);
				this.addFlash(el, props);
			}, this);
		}
	}
});
/************************************************************/